import * as domains from './env.js'

export default {
  /**
   * 获取图片完整URL
   * @param {*} url 
   */
  imgUrl(url){
    return domains.img() + url
  },
  /**
   * 通过商品ID获取图片
   * @param {*} id 商品id
   */
  cimgUrl(id){
    return `${domains.img()}/uimg/cmws/catentries/${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
  },
  /**
   * 获取B2C商品图片
   * @param {*} id 
   */
  b2cimgUrl(id) {
    return `${domains.img()}/b2c/catentries/${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
  },
  spimgUrl(id,type) {
    let url
    if (type == '0') {
      url = `${domains.img()}/b2c/catentries/${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
    }else {
      url = `${domains.img()}/uimg/cmws/catentries/${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
    }
    return url
  },
  newImgUrl(id,type) {
    let url
    if(type == '0') {
      url =`${domains.img()}/uimg/cmws/catentries/uimg/b2c/newcatentries/0000000000-${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
    }
    else{
      url = `${domains.img()}/uimg/cmws/catentries/${id.replace(/(^\s*)|(\s*$)/g, '')}_1_400x400.jpg`
    }
    return url
  },
  /**
   * 价格精确到小数点后两位数
   * @param {*} id 
   */
  formatPrice(price){
    var p = price || 0;
    return parseFloat(p).toFixed(2)
  },

  // 手机号加密
  phoneCoded(tmp) {
    if(!tmp)return
    var reg = /^(\d{3})\d{4}(\d{4})$/;
    return tmp.replace(reg, "$1****$2");
  }
  
}
